/**
 * 字段审计日志查询列表面板
 */
Ext.namespace("Ext.ux.syslog");

Ext.ux.syslog.PropAuditQueryPanel = Ext.extend(Ext.Panel, {

	border: false,
	region: 'center',
	layout: 'border',

	formPanel: null,
    grid: null,
	
	initComponent:function(){
		Ext.ux.syslog.PropAuditQueryPanel.superclass.initComponent.call(this);
		
		//查询部分
		var searchForm = new Ext.FormPanel({
			region: 'north',
			title: '字段审计日志查询',
			labelAlign: 'right',
			height: 60,
			frame: true,
			plain: true,
			collapsible: true,
			border: true,
			margins: '1 1 2 1',
			items: [{
				layout: 'column',
				items:[{
					columnWidth: .33,
					layout: 'form',
					items: [{
						xtype: 'textfield',
						fieldLabel: '值对象名称',
						name: 'entity',
						anchor: '95%'
					}]
				},{
					columnWidth: .33,
					layout: 'form',
					items:[{
						xtype: 'textfield',
						fieldLabel: '值对象主键',
						name: 'entityId',
						anchor: '95%'
					}]
				},{
					columnWidth: .33,
					layout: 'hbox',
					defaults:{margins:'0 5 0 0'},
					items:[{
						xtype: 'button',
						text: '查询',
						width: 80,
						handler: this.search,
						scope: this
					},{
						xtype: 'button',
						text: '清空',
						width: 80,
						handler: this.clearSearchForm,
						scope: this
					}]
				}]
			}]
		});
		this.add(searchForm);
		this.formPanel = searchForm;
	
		
		// 列表部分
		var gridStructure = [{  
			name: 'id',
			hidden: true
		},{
			name: 'entity',  
			header: "值对象名称",
			sortable: true,
			width: 120
		},{  
			name: 'entityId',  
			header: "值对象主键",
			sortable: true,
			width: 100
		},{  
			name: 'propertyName',  
			header: "属性名称",
			sortable: true,
			width: 120
		},{  
			name: 'propertyComment',  
			header: "属性中文注释",
			sortable: true,
			width: 120
		},{  
			name: 'oldValue',  
			header: "旧值",
			sortable: true,
			width: 150
		},{  
			name: 'newValue',  
			header: "新值",
			sortable: true,
			width: 150
		},{  
			name: 'updator',  
			header: "修改人",
			sortable: true,
			width: 100
		},{  
			name: 'updateTime',  
			header: "修改时间",
			sortable: true,
			type: 'datetime',
			width: 120
		},{
			name: 'memo',  
			header: "备注",
			width: 150
		}];
	   
		var grid = new Ext.ux.grid.CrudGrid({
			title: '字段审计日志列表',
			region: 'center',
			margins: '0 1 1 1',
			structure: gridStructure,
			url: 'sys-prop-audit-log!list.action',
			defaultSortField: 'updateTime',
			defaultSortDir: 'desc',
			keyField: 'id',
			showAddBtn: false,
			showUpdateBtn: false
		});
		
		grid.on('rowdblclick', function(grid, rowIndex, e){
			var sel = grid.getSelectionModel().getSelections();
			var id = sel[0].get('id');
			this.loadById(id);
		}, this);

		grid.on('deleteRecord', function(grid, ids){
			Ext.Ajax.request({
				url: 'sys-prop-audit-log!delete.action',
				success: function(responese){
					this.search();
					Ext.Msg.alert('系统提示', '已成功删除选中的附件记录！');
				},
				failure: function(){
					Ext.Msg.alert('系统提示', '删除失败');
				},
				method: 'POST',
				params:{
					ids: ids
				},
				scope: this
			});
		}, this);
	
		this.add(grid);
		this.grid = grid;
	
		grid.store.on('beforeload', function(){
			grid.store.baseParams = {
				entity: this.formPanel.form.findField('entity').getValue(),
				entityId: this.formPanel.form.findField('entityId').getValue()
			};
		}, this);
	},
	
	//查询
	search: function(){
		this.grid.store.reload();
	},
	
	//清空查询条件
	clearSearchForm: function(){
		this.formPanel.form.reset();
		this.formPanel.form.findField('entity').focus();
		this.search();
	},
	
	//加载附件信息
	loadById: function(id){
		var win = new Ext.ux.syslog.PropAuditDetailWindow({title:'查看字段审计日志'});
		win.loadById(id);
	}
});